using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.PlayerLoop;

namespace Platform.Skill.Deployer
{


    /// <summary>
    /// 抛物线技能释放器
    /// </summary>
    public class ParabolicSkillDeployer : SkillDeployer
    {
        public Player player;

        protected Collider2D cd;

        protected Vector2 finalDir;


        void Awake()
        {
            anim = GetComponentInChildren<Animator>();
            rb = GetComponent<Rigidbody2D>();
            cd = GetComponent<Collider2D>();
            // cd = GetComponent<CircleCollider2D>();
            player = GameMgr.Instance.player;
        }

        void Start()
        {
            player = GameMgr.Instance.player;
        }

        void Update()
        {

        }

        void OnEnable()
        {
            cd.enabled = true;
            rb.isKinematic = false;
            rb.constraints = RigidbodyConstraints2D.None;
        }

       
       
        // 由效果决定是否冻结
        public virtual void StopRigidbody()
        {
            cd.enabled = false;
            rb.isKinematic = true;
            // 冻结所有 自由度（位置和旋转）
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
        }


        public override void DeploySkill()
        {
            finalDir = new Vector2(Tool.GetMouseDirection().normalized.x * skillData.launchForce.x,
                   Tool.GetMouseDirection().normalized.y * skillData.launchForce.y);
            rb.velocity = finalDir;
            rb.gravityScale = skillData.gravity;

            base.DeploySkill();
        }

        /// <summary>
        /// 让效果只依赖此接口
        /// </summary>
        public virtual void ReturnSword() { }
        public virtual void SetRotate(bool value) { }
    }
}